#include<bits/stdc++.h>
#define endl '\n' 
#define ll long long
using namespace std;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
const int N = 51,inf = 1e9;

int n,m,k,E;
int A,B,C,D;

char g[N][N];
vector<vector<int>> d(N,vector<int>(N,inf)),vis(N,vector<int>(N,0));

int cost[N][N];

pair<int,int> port[N][N];

struct Node{
	int x,y,w;
	bool operator < (const Node &u) const{
		return w > u.w;
	}
};

void dijkstra()
{
	priority_queue<Node> pq;
	pq.push({A,B,d[A][B] = 0});
	while(!pq.empty()){
		auto [x,y,w] = pq.top();
		pq.pop();
		if(vis[x][y]) continue;
		for(int i = 0;i < 4;i ++){
			int xx = x + dx[i],yy = y + dy[i];
			if(xx <= 0 || xx > n || yy <= 0 || yy > m || g[xx][yy] == '#') continue;
			
			if(d[xx][yy] > d[x][y] + 1){
				d[xx][yy] = d[x][y] + 1;
				pq.push({xx,yy,d[xx][yy]});
			}
			
			if(cost[xx][yy]){
				auto [tx,ty] = port[xx][yy];
				if(d[tx][ty] > d[xx][yy] + cost[xx][yy]){
					d[tx][ty] = d[xx][yy] + cost[xx][yy];
					pq.push({tx,ty,d[tx][ty]});
				}
			}
		}
	}
}

void solve()
{
	cin >> n >> m >> A >> B >> C >> D;
	for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= m;j ++){
			cin >> g[i][j];
		}
	}
	cin >> k;
	for(int i = 0;i < k;i ++){
		int x,y,tx,ty,p;
		cin >> x >> y >> tx >> ty >> p;
		port[x][y] = {tx,ty};
		cost[x][y] = p;
	}
	cin >> E;
	dijkstra();
	if(d[C][D] >= inf || d[C][D] > E) cout << -1 << endl;
	else cout << E - d[C][D] << endl;
}


int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _; // cin >> _;
	_ = 1;
	while(_ --) solve();
	
	return 0;
}
